package com.api.gbhg.lbj.liubeijia.workflowaction;

import com.api.gbhg.lbj.liubeijia.util.GBHGConstant2;
import com.api.gbhg.lbj.liubeijia.util.VersionFlowUtil2;

import com.weaver.general.BaseBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSetTrans;
import weaver.general.GCONST;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;



/**
 * @author lbj
 * @version 1.0
 * @description: TODO预算同步版本表，经费表uf_jingfei和 uf_jingfei_version
 * @date 2022/6/24 10:35
 */
public class BudgetSyncAction implements Action {
    private static final Logger logger = LoggerFactory.getLogger("gbhg");
    private String flowtype;

    public String getFlowtype() {
        return flowtype;
    }

    public void setFlowtype(String flowtype) {
        this.flowtype = flowtype;
    }

    @Override
    public String execute(RequestInfo requestInfo) {
        //String flowtype = this.getFlowtype();
        String flowtype2 = "";
        String thisVersion = "";
        Property[] properties = requestInfo.getMainTableInfo().getProperty();
        for(Property property : properties){
            if(property.getName().equals("flowtype")){
                flowtype2 = property.getValue();
            }else if(property.getName().equals("version")){
                thisVersion = property.getValue();
            }
        }
        logger.info("进入预算调整/编制-同步版本表--flowtype---"+flowtype2);
        if(flowtype2.equals("") || flowtype2.equals("null")){
            requestInfo.getRequestManager().setMessagecontent("预算版本表同步异常 未获取到表单flowtype");
            requestInfo.getRequestManager().setMessageid("1");
            return FAILURE_AND_CONTINUE;
        }
        String flowVersionTableName = GBHGConstant2.getEnumByValue(flowtype2).getFlowVersionTableName();
        logger.info("同步的备份表名---"+flowVersionTableName);

        Boolean bo=VersionFlowUtil2.sysDataToVersion2(requestInfo.getRequestid(),requestInfo.getWorkflowid(),GBHGConstant2.getEnumByValue(flowtype2) ,null,thisVersion);
        logger.info("----测试进入预算版本表同步----");
        if (!bo){
            requestInfo.getRequestManager().setMessagecontent("预算版本表同步异常");
            requestInfo.getRequestManager().setMessageid("1");
            return FAILURE_AND_CONTINUE;
        }
        return Action.SUCCESS;
    }

    public static void main(String[] args) {

        String rootPath = "D:\\WEAVER\\ecology\\";
        GCONST.setRootPath(rootPath);
        GCONST.setServerName("ecology");

        Boolean bo=VersionFlowUtil2.sysDataToVersion2("2248723","429",GBHGConstant2.getEnumByValue("02") ,null,"4");

       System.err.println(bo);
    }
}
